package com.moss.web;


import com.github.pagehelper.PageInfo;
import com.moss.common.core.BaseController;
import com.moss.common.domain.AjaxResult;
import com.moss.common.entity.SysSampleOrgEntity;
import com.moss.system.service.SampleOrgService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("/sampleOrg")
public class SampleOrgController extends BaseController {

    @Resource
    SampleOrgService sampleOrgService;


    @GetMapping("/list")
    private AjaxResult<List<SysSampleOrgEntity>> listSampleOrg(SysSampleOrgEntity sampleOrg){
        startPage();
        List<SysSampleOrgEntity> list = sampleOrgService.listSampleOrg(sampleOrg);
        return AjaxResult.success(list,new PageInfo<>(list).getTotal());
    }

    @PostMapping("/add")
    public AjaxResult<Void> saveSampleOrg(@RequestBody @Validated SysSampleOrgEntity sampleOrg){
        sampleOrg.setCreateBy(getUserId());
        sampleOrgService.saveSampleOrg(sampleOrg);
        return AjaxResult.success();
    }

    @GetMapping("/{id}")
    public AjaxResult<SysSampleOrgEntity> getSampleOrg(@PathVariable Long id){
        return AjaxResult.success(sampleOrgService.getSampleOrg(id));
    }

    @PostMapping("/update")
    public AjaxResult<Void> updateSampleOrg(@RequestBody @Validated SysSampleOrgEntity sampleOrg){
        sampleOrg.setUpdateBy(getUserId());
        sampleOrgService.updateSampleOrg(sampleOrg);
        return AjaxResult.success();
    }


    @DeleteMapping("/{ids}")
    public AjaxResult<Void> deleteSampleOrg(@PathVariable @NotEmpty(message = "请选中需要删除的数据") Long[] ids){
        sampleOrgService.deleteSampleOrg(ids);
        return AjaxResult.success();
    }
}
